public class Peopletest41 {
    public static void main(String[] args) {


//1.创建一个数组来储存学生对象
        People[] arr = new People[3];
//2.创建学生对象并添加到数组中
        People stu1 = new People(1, "zhang", 21);
        People stu2 = new People(2, "wang", 23);
        People stu3 = new People(3, "zhao", 22);
//3.把学生添加到数组中
        arr[0] = stu1;
        arr[1] = stu2;
        arr[2] = stu3;
        //要求3:通过id删除学生信息 如果存在则删除 如果不存在,则提示删除失败
        //找到id在数组中所对应的索引
        int index = getIndex(arr,2);
        if(index >= 0){
            arr[index] = null;
           getArr(arr);
        }
        else{
            System.out.println("该id不存在");
        }
    }

    //要干什么 找到id在数组中所对应的索引
    //需要什么 数组,id
    //调用处是否继续使用方法的结果  需要
    public static int getIndex(People[] arr,int id) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null){
                int pid = arr[i].getId();
                if(pid == id) {
                    return i;
                }
            }
        }
                return -1;
    }
    public static void getArr(People[] arr){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null){
                System.out.println(arr[i].getId()+","+arr[i].getName()+","+arr[i].getAge());
            }
        }
    }
}